﻿using System;
using Missbot.Service;
using MongoDB.Bson.Serialization.Attributes;

namespace Missbot.AIModule.Gaming.Gift
{
    /// <summary>
    /// 魅力记录
    /// </summary>
    [BsonIgnoreExtraElements]
    public class GlamourRecord : DbBaseEntity
    {
        /// <summary>
        /// 群组ID
        /// </summary>
        public string GroupID { get; init; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserID { get; init; }

        /// <summary>
        /// 魅力值
        /// </summary>
        public int Glamour { get; set; }

        /// <summary>
        /// 过期时间
        /// </summary>
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime? ExpiryTime { get; set; }
    }

    public static class GlamourRecordDA
    {
        /// <summary>
        /// 按群组ID和用户ID获取魅力记录
        /// </summary>
        /// <param name="GroupID"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static GlamourRecord Get(string GroupID, string UserID)
        {
            var record = MongoService<GlamourRecord>.GetOnly(p => p.GroupID == GroupID && p.UserID == UserID);
            if (record != null)
            {
                return record;
            }

            record = new GlamourRecord {GroupID = GroupID, UserID = UserID};
            MongoService<GlamourRecord>.Insert(record);

            return record;
        }

        /// <summary>
        /// 更新
        /// </summary>
        public static void Update(this GlamourRecord entity)
        {
            MongoService<GlamourRecord>.Update(entity);
        }
    }
}